package cloud.zhixinglu.www.spring.boot.mybatis.plus.service.impl;

import cloud.zhixinglu.www.spring.boot.mybatis.plus.entity.TestEntity;
import cloud.zhixinglu.www.spring.boot.mybatis.plus.mapper.TestMapper;
import cloud.zhixinglu.www.spring.boot.mybatis.plus.service.TestService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author WeiXin
 * @since 2023-08-14 16:06:18
 */
@Service
public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> implements TestService {

    @Resource
    private TestMapper mapper;

    @Override
    public TestEntity getTestByOperationId(String operationId) {
        LambdaQueryWrapper<TestEntity> qw = new LambdaQueryWrapper<>();
        qw.eq(TestEntity::getOperationId, operationId)
                .last("limit 1");
        return mapper.selectOne(qw);
    }

    /**
     * 获取
     *
     * @param operationId {@link String} 操作ID
     * @return List<TestVO>
     */
    @Override
    public List<TestEntity> getTestListByOperationId(String operationId) {
        LambdaQueryWrapper<TestEntity> qw = new LambdaQueryWrapper<>();
        qw.eq(TestEntity::getOperationId, operationId)
                .orderByAsc(TestEntity::getBusinessSend);
        return mapper.selectList(qw);
    }

    @Override
    public List<TestEntity> getTestAllList() {
        LambdaQueryWrapper<TestEntity> qw = new LambdaQueryWrapper<>();
        qw.orderByDesc(TestEntity::getBusinessSend).last("limit 100");
        return mapper.selectList(qw);
    }

    @Override
    public Page<TestEntity> pageTestListDesc(Page<TestEntity> page) {
        LambdaQueryWrapper<TestEntity> qw = new LambdaQueryWrapper<>();
        qw.orderByAsc(TestEntity::getBusinessSend);
        return mapper.selectPage(page, qw);
    }

}
